<table class="table table-hover p-table">
          <thead>
          <tr>
              <th>id</th>
              <th>品牌名称</th>
              <th>上传日期</th>
              <th>操作</th>
          </tr>
          </thead>
          <tbody>
          		<?php if(empty($data)) {?>  
                  <tr><td style="text-align: center;" colspan="5">查询不到相关数据</td></tr> 
              <?php }?>  
           <foreach name="data" item="v" key="k">
              <tr>
              	  <td>{$v.id}</td>
                  <td>
                      <a>{$v.name}</a>
                  </td>
                  <td>{$v.add_time|date='Y-m-d H:i',###}</td>
                  <td>
                  	   <button class="btn btn-success btn-xs" data-toggle="modal" onclick="edit('{$v.name}',{$v.id});"><i class="icon-edit"></i>编辑</button>
                      <span class="btn btn-danger btn-xs" onclick="del({$v.id})"><i class="icon-trash"></i>删除</span>
                  </td>
              </tr>
             </foreach>
          </tbody>
</table>
<div class="row">
  <div class="col-xs-12 text-center">{$page}</div>
</div>

  		<!--新建品牌Modal） -->
	        <div class="modal fade" id="add_brand" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                  <div class="modal-content">
                      <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                          <h4 class="modal-title">新增品牌</h4>
                      </div>
                          <div class="modal-body">
                           <div class="form-group">
                              <label class="col-sm-3 control-label">请输入品牌名称</label>
                              <div class="col-sm-9">
                                  <input type="text" class="form-control" value="" id="brand_add">
                              </div>
                          </div>
                         </div>
                      <div class="modal-footer">
                          <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                          <button class="btn btn-submit" type="button" onclick="add_brand()">添加</button>
                      </div>
                  </div>
              </div>
          </div>
             <!--编辑文件夹（Modal） -->
	        <div class="modal fade" id="edit_brand" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                  <div class="modal-content">
                      <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                          <h4 class="modal-title">重命名</h4>
                      </div>
                          <div class="modal-body">
                           <div class="form-group">
                              <label class="col-sm-3 control-label">请输入品牌名称</label>
                              <div class="col-sm-9">
                                  <input type="text" class="form-control" value="" name="bname">
                                  <input type="hidden" class="form-control" value="" name="id">
                              </div>
                          </div>
                         </div>
                      <div class="modal-footer">
                          <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                          <button class="btn btn-submit" type="button" onclick="edit_brand()">修改</button>
                      </div>
                  </div>
              </div>
          </div>
<script>
$(".pagination  a").click(function(){
    var page = $(this).data('p');
    ajaxgover(page);
});

function edit(o,id){
	$("input[name='bname']").attr('value',o);
	$("input[name='id']").attr('value',id);
	$('#edit_brand').modal('show');
}

// 新增品牌
function add_brand(){
	var name = $('#brand_add').val();
	var act = 'add';
	if(name==''){
		layer.msg('品牌名称不能为空',{icon:2});
		return;
	}
	 $.ajax({
         type : "POST",
         url:'__URL__/aebrand',
         data : {name:name,act:act},
         dataType : 'json',
         success: function(res){
       	  if(res.status==0){
				layer.alert(res.info, {icon: 2});
				return;
			 }
	       if(!res.errNo){
		     layer.msg(res.msg,{icon:1});
			 setTimeout("location.reload()",2000);
          }else{
        	 layer.msg(res.msg,{icon:2});
          }
         }
     });
}

//编辑品牌
function edit_brand(){
	var name = $("input[name='bname']").val();
	var id = $("input[name='id']").val();
	var act = 'edit';
	if(name==''){
		layer.msg('品牌名称不能为空',{icon:2});
		return;
	}
	 $.ajax({
         type : "POST",
         url:'__URL__/aebrand',
         data : {name:name,act:act,id:id},
         dataType : 'json',
         success: function(res){
       	  if(res.status==0){
				layer.alert(res.info, {icon: 2});
				return;
			 }
	       if(!res.errNo){
		     layer.msg(res.msg,{icon:1});
			 setTimeout("location.reload()",2000);
          }else{
        	 layer.msg(res.msg,{icon:2});
          }
         }
     });
}
//删除
function del(id){
	  if(!id){
		 layer.msg('id获取失败',{icon:2});
  		 return false;
	 }
	  var act = 'del';
		layer.confirm('删除后不可恢复,您确认删除吗？', {
		  btn: ['确定','取消'] //按钮
		}, function(){
		 $.ajax({
		 		type : 'post',
		 		url:'__URL__/del',
		 		data : {id:id},
		 		dataType : 'json',
		 		success : function(res){
		 			 if(res.status==0){
						layer.alert(res.info, {icon: 2});
						return;
					 }
		 			 if(!res.errNo){
		 				 layer.msg(res.msg,{icon:1});
		 				 setTimeout("location.reload()",2000);
			          }else{
			        	 layer.msg(res.msg,{icon:2});
			          }
		 		}
		     })
		}, function(index){
			layer.close(index);
			return false;// 取消
		}
		);
}

</script>
